**********Syntax file for Anoll, Allison P., Cindy D. Kam, and Colette Marcellin. "What Does Race Mean?  Racial Disparities in the Public Mind." Journal of Politics**********

*****Analysis with StataSE17*****
*****Note: requires installation of "catplot" and "coefplot"*****

log using "Anoll Kam Marcellin Lucid Analyses.smcl", replace

clear
cd "C:/users/kamcd/Dropbox/CDK WORK/racial disparities essentialism/JOP replication files"

*Saved csv file as an excel workbook
*reading in the excel data
use "Anoll Kam Marcellin Lucid March 2021 Survey.dta", clear

*****Coding Covariates*****
//age
gen age01 = (age-18)/(93-18)
lab var age01 "Age"

//educ
gen ed6cat = (educ-1)/5
lab def ed6cat 0"Less HS" 1">BA"
lab val ed6cat ed6cat
lab var ed6cat "Education"

//female
recode gender (1=1 "female")(2=0)(else=.), gen(female)

//race
gen race_all = .
replace race_all = 1 if race_1==1
replace race_all = 2 if race_2==1
replace race_all = 4 if race_4==1|race_6==1
replace race_all = 3 if hisp_2==1|hisp_3==1|hisp_4==1|hisp_5==1
lab def race_all 1"White" 2"Black" 3"Hispanic any race" 4"AAPI"
lab val race_all race_all
tab race_all

recode race_all (1=1)(2/4=0)(else=.), gen(white)
recode race_all (2=1)(1 3 4=0)(else=.), gen(black)
recode race_all (3=1)(1 2 4=0)(else=.), gen(hispanic)
recode race_all (4=1)(1 2 3=0)(else=.), gen(api)
lab var black "Black"
lab var hispanic "Latino"
lab var api "Asian"

//party 
gen pid7cata = .
replace pid7cata = 0 if demf==1
replace pid7cata = .17 if demf==2
replace pid7cata = .33 if indf==2
replace pid7cata = .5 if indf==3
replace pid7cata = .67 if indf==1
replace pid7cata = .83 if gopf==2
replace pid7cata = 1 if gopf==1
tab pid7cata
lab var pid7cata "Party ID"

recode pid7cata (0/.4=1)(.5/1=0)(else=.), gen(dem)
recode pid7cata (0/.51=0)(.6/1=1)(else=.), gen(rep)
recode pid7cata (0/.34=0)(.5=.5)(.6/1=1)(else=.), gen(pid3cata)
recode pid7cata (0/.34=0 "Dem")(.5=.)(.6/1=1 "GOP")(else=.), gen(pid2cata)
lab var pid2cata "Dem (0) or GOP (1)"

//Five analytical groups
gen fivegroups = .
replace fivegroups = 1 if api==1
replace fivegroups = 2 if black==1
replace fivegroups = 3 if hispanic==1
replace fivegroups = 4 if white==1 & pid2cata==0
replace fivegroups = 5 if white==1 & pid2cata==1
lab def fivegroups 1"Asian" 2"Black" 3"Latino" 4"White DEM" 5"White GOP"
lab val fivegroups fivegroups
tab fivegroups

//*Question 3: what determines your own race battery
recode moduleC_2_1 moduleC_2_2 moduleC_2_3 moduleC_2_4 moduleC_2_5 moduleC_2_6 moduleC_2_7 (1=1)(2=0)(3=0)(4=0), gen(myrace_DNA myrace_culture myrace_history myrace_choices myrace_forms myrace_toldme myrace_physical)
lab def myrace 1"Strongly" 0"Not strongly", modify
lab val myrace_DNA myrace_culture myrace_history myrace_choices myrace_forms myrace_toldme myrace_physical myrace  
sum myrace_DNA myrace_culture myrace_history myrace_choices myrace_forms myrace_toldme myrace_physical

//recoding to capture folks who state strongly or somewhat
//combining No and DK together
recode moduleC_2_1 moduleC_2_2 moduleC_2_3 moduleC_2_4 moduleC_2_5 moduleC_2_6 moduleC_2_7 (1 2=1)(3 4=0), gen(myrace_DNA2 myrace_culture2 myrace_history2 myrace_choices2 myrace_forms2 myrace_toldme2 myrace_physical2)
lab def myrace2 1"Strongly or somewhat" 0"Not at all"
lab val myrace_DNA2 myrace_culture2 myrace_history2 myrace_choices2 myrace_forms2 myrace_toldme2 myrace_physical2 myrace2

//% DK/ref
tab1 moduleC_2_1- moduleC_2_7
egen ref_myrace = anycount(moduleC_2_1- moduleC_2_7), val(4)
tab ref_myrace

forval v=1/7 {
recode moduleC_2_`v' (1 2=1)(3 4 =0)(else=.), gen(myraceagree`v')
}

set scheme s1mono

**********START FIGURE 1**********
//Figure 1. Agree + Strongly Agree, by racial group
forval v=1/7 {
recode moduleC_2_`v' (1=1)(2 3 4 =0)(else=.), gen(myraceSTRagree`v')
}

forval v=1/7 {
recode moduleC_2_`v' (2=1)(1 3 4 =0)(else=.), gen(myraceONLYagree`v')
}

//for text, % by fivegroups:
tab myraceagree1 fivegroups, col
tab myraceSTRagree1 fivegroups, col

//% STRONGLY AGREE BY FIVEGROUPS
forval v=1/5 {
preserve
collapse myraceSTRagree1-myraceSTRagree7 if fivegroups==`v'
gen id = _n
reshape long myraceSTRagree, i(id) j(Q)
lab def Q 1 "DNA" 2 "Culture" 3 "History" 4 "My Choices" 5 "Select on Forms" 6 "What Someone Told Me" 7"Physical Traits"
lab val Q Q
gen myraceSTRagreepercent_`v' = myraceSTRagree*100
save myraceSTRagreepercent_`v', replace
restore
}

//% AGREE BY FIVEGROUPS
forval v=1/5 {
preserve
collapse myraceONLYagree1-myraceONLYagree7 if fivegroups==`v'
gen id = _n
reshape long myraceONLYagree, i(id) j(Q)
lab def Q 1 "DNA" 2 "Culture" 3 "History" 4 "My Choices" 5 "Select on Forms" 6 "What Someone Told Me" 7"Physical Traits"
lab val Q Q
gen myraceONLYagreepercent_`v' = myraceONLYagree*100
save myraceONLYagreepercent_`v', replace
restore
}

//PLOTTING %STR AGREE + AGREE BY FIVEGROUPS
forval v=1/5 {
preserve
clear
use myraceSTRagreepercent_`v', clear
	gen str10 group`v' = "Asian" if `v'==1
	replace group`v' = "Black" if `v'==2
	replace group`v' = "Latino" if `v'==3
	replace group`v' = "White DEM" if `v'==4
	replace group`v' = "White GOP" if `v'==5
	local h = group`v'
merge 1:1 Q using myraceONLYagreepercent_`v'
recode Q (1=1 "DNA")(7=2 "Phys Traits")(3=3 "History")(2=4 "Culture") (5=5 "Forms")(4=6 "Choices")(6=7 "Told Me"), gen(graphorder)
graph hbar myraceSTRagreepercent myraceONLYagreepercent, over(graphorder) ///
name(myraceboth_`v', replace) ///
title("`h' Respondents", size(medium)) ytitle(" ") xsize(5) ysize(4) graphregion(margin(l+10)) stack asyvars legend(lab(1 "% Strongly") lab(2 "% Somewhat") symxsize(5) keygap(.5) forcesize)
restore
}

graph combine myraceboth_1 myraceboth_2 myraceboth_3 myraceboth_4 myraceboth_5, row(2) title("To what extent do the following factors determine your race?", size(medium)) xsize(6.5) ysize(4.5) imargin(medium) iscale(.55) ycommon xcommon
graph export Figure1.pdf, replace
**********END FIGURE 1**********

*****cleaning up directory*****
forval v=1/5 {
erase myraceSTRagreepercent_`v'.dta
erase myraceONLYagreepercent_`v'.dta
}

*****FN 11: PAIRWISE COMPARISONS*****
//Difference of proportions test
//create comparison groups
gen AB = .
replace AB=1 if fivegroups==1|fivegroups==2
gen AL = .
replace AL=1 if fivegroups==1|fivegroups==3
gen AWD = .
replace AWD=1 if fivegroups==1|fivegroups==4
gen AWR = .
replace AWR=1 if fivegroups==1|fivegroups==5
gen BL = .
replace BL=1 if fivegroups==2|fivegroups==3
gen BWD = .
replace BWD=1 if fivegroups==2|fivegroups==4
gen BWR = .
replace BWR=1 if fivegroups==2|fivegroups==5
gen LWD = .
replace LWD=1 if fivegroups==3|fivegroups==4
gen LWR = .
replace LWR=1 if fivegroups==3|fivegroups==5
gen WDR = .
replace WDR=1 if fivegroups==4|fivegroups==5

*****Strongly or Somewhat: DNA*****
*****Multiple Factors*****
egen howmanyagree = anycount(myrace_DNA2 myrace_culture2 myrace_history2 myrace_choices2 myrace_physical2 myrace_forms2 myrace_toldme2 ), val(1)
recode howmanyagree (0 1=0)(2/7=1 "Selected Agree with More than One Item"), gen(morethanone)

*****"Opposing" Factors: DNA plus any constructivist (culture, history, choices, forms, told me)*****
egen anyconstructivist = anymatch(myrace_culture2 myrace_history2 myrace_choices2 myrace_forms2 myrace_toldme2), val(1)
gen DNAanycon= anyconstructivist +myrace_DNA2
replace DNAanycon = 0 if DNAanycon==1
replace DNAanycon =1 if DNAanycon==2

lab var morethanone "Proportion Agreeing with >1 Factor"
lab var DNAanycon "Proportion Agreeing with DNA + Any Constructivist Factor"
lab var myrace_DNA2 "Proportion Agreeing with DNA"
lab var myrace_DNA "Proportion Strongly Agreeing with DNA"
lab var fivegroups "Subgroups"

*****In text*****
tab fivegroups morethanone, row
tab fivegroups DNAanycon, row

*****PAIRWISE DIFFERENCE OF PROPORTIONS TESTS (FOR APPENDIX)*****
foreach y of varlist myrace_DNA2 myrace_DNA morethanone DNAanycon {
	disp "TESTS FOR VARIABLE: `y'"
	foreach v of varlist AB-WDR {
		prtest `y' if `v'==1, by(fivegroups)
	}
	}

**********START FIGURE 2**********
foreach y of varlist morethanone DNAanycon {
tempname memhold
tempfile `y'
postfile `memhold' fivegroups propagree seprop using `y', replace
forval v=1/5 {
	reg `y' if fivegroups==`v'
	post `memhold ' (`v') (_b[_cons]) (_se[_cons])
}
postclose `memhold'
}

preserve
use morethanone, clear
lab def fivegroups 1"Asian" 2"Black" 3"Latino" 4"White DEM" 5"White GOP"
lab val fivegroups fivegroups
gen UB = propagree + 1.96*seprop
gen LB = propagree - 1.96*seprop
twoway (bar propagree fivegroups, fcolor(gs8)) (rcap UB LB fivegroups, lcolor(black)), xlabel(, valuelabel) xtitle(" ") legend(off) ylabel(0(.25)1) title("(a) Proportion Agree with >1 Factor to Define Race") name(morethanone, replace)

use DNAanycon, clear
lab def fivegroups 1"Asian" 2"Black" 3"Latino" 4"White DEM" 5"White GOP"
lab val fivegroups fivegroups
gen UB = propagree + 1.96*seprop
gen LB = propagree - 1.96*seprop
twoway (bar propagree fivegroups, fcolor(gs8)) (rcap UB LB fivegroups, lcolor(black)), xlabel(, valuelabel) xtitle(" ") legend(off) ylabel(0(.25)1) title("(b) Proportion Agree with 'Conflicting' Factors to Define Race") name(DNAanycon, replace)

graph combine morethanone DNAanycon, row(1) col(2) iscale(.7) imargin(r+10 l+5) xsize(6.5) ysize(2.5) 
graph export Figure2.pdf, replace
restore
**********END FIGURE 2**********

*****cleaning up directory*****
erase DNAanycon.dta
erase morethanone.dta 

**********BIOLOGICAL DETERMINISM**********
recode moduleC_scale (1=1 "All biology")(2=.75)(3=.5)(4=.25)(5=0 "Identity totally separate")(else=.), gen(race_bio_identity)

gen race_bio_graph= -1*(moduleC_scale-5)
lab def race_bio_graph 0 "Racial identity is totally separate from biology" 1 "Racial identity is somewhat separate from biology" 2 "Racial identity is tied to your biology but not determined by it" 3 "Biology somewhat determines your racial identity" 4 "Biology totally determines your racial identity", modify
lab val race_bio_graph race_bio_graph

*****in text*****
tab race_bio_graph fivegroups, col
*range on somewhat + totally, Low & Hi: 34 to 55%
disp 17.97+25.52
disp 32.10+23.08

*****PAIRWISE DIFFERENCE OF MEANS TESTS
foreach v of varlist AB-WDR {
		ttest race_bio_identity if `v'==1, by(fivegroups)
	}

**********START FIGURE 3**********	
catplot, over(race_bio_identity) over(fivegroups) percent(fivegroups) recast(hbar) stack asyvars legend(lab(1 "Racial identity totally separate from biology") lab(2 "Racial identity somewhat separate from biology") lab(3 "Racial identity is tied to your biology but not determined by it") lab(4 "Biology somewhat determines your racial identity") lab(5 "Biology totally determines your racial identity") row(5)) xsize(8) ysize(7) legend(size(*.7))
graph export Figure3.pdf, replace
**********END FIGURE 3**********

**********COVID-19 ATTRIBUTIONS**********
recode ModuleB_a ModuleB_b ModuleB_c ModuleB_d ModuleB_e ModuleB_f (1=1)(2=.67)(3=.33)(4=0)(else=.), gen(covid_gene covid_preexisting covid_jobs covid_healthcare covid_neighborhood covid_flout_protocols)

/*Taking out those who refuse the entire battery*/
egen ref_covid_battery = anycount(ModuleB_a-ModuleB_f), val(4)
tab ref_covid_battery
//23 people refused to acknowledge any of the factors as accounting for racial disparities

**********START FIGURE 4**********
/*ANALYSES WITH RAKED WEIGHTS*/
//creating weight - survey raking
//adjust for the five groups
//using CES 2021 as the benchmark for controls

svycal regress i.fivegroup, generate(fivegroup_weight) totals(909 3301 3320 6144 7508 21182, copy)
svyset [pweight=fivegroup_weight]
recode fivegroups (4=1)(1/3 5=0)(else=.), gen(WDem)
recode fivegroups (5=1)(1/4 =0)(else=.), gen(WRep)

foreach v of varlist covid_gene covid_preexisting covid_jobs covid_healthcare covid_neighborhood covid_flout_protocols {
svy: reg `v' race_bio_identity pid7cata ed6cat age01 black hispanic api WDem if ref_covid_battery~=6
est store `v'_wt
}
coefplot covid_gene_wt covid_flout_protocols_wt covid_neighborhood_wt covid_jobs_wt covid_healthcare_wt covid_preexisting_wt, keep(race_bio_identity) xline(0, lcolor(red) lpattern(dash) ) ///
legend(position(3) row(6) region(margin(r+5))) coeflabels(race_bio_identity=" ", noticks) ///
plotlabels(`" " ""Genetic Differences"" ""' `" " ""Flout Protocols"" " "' `" " ""Neighborhood Hot Spots"" " "'  `" " ""Occupational Hazards"" " "' `" " ""Healthcare Access"" " "' `" " ""Preexisting Conditions"" ""' ) ///
title("DVs: Explanations for COVID-19 Racial Disparities" "OLS Coefficient on Defining Race as Biology", size(medium)) xsize(10) ysize(7)
graph export Figure4.pdf, replace
**********END FIGURE 4**********

**********FOR APPENDIX**********
est table covid_gene_wt covid_preexisting_wt covid_jobs_wt covid_healthcare_wt covid_neighborhood_wt covid_flout_protocols_wt , b(%9.2f) se style(col) eq(1) stats(N) modelwidth(1)
est table covid_gene_wt covid_preexisting_wt covid_jobs_wt covid_healthcare_wt covid_neighborhood_wt covid_flout_protocols_wt , b(%9.2f) star(.05 .01 .001) style(col) eq(1) stats(N)

//New model separately by five groups
forval j=1/5 {
	foreach v of varlist covid_gene covid_preexisting covid_jobs covid_healthcare covid_neighborhood covid_flout_protocols {
	reg `v' race_bio_identity pid7cata ed6cat age01 black hispanic api if fivegroups==`j' & ref_covid_battery~=6
est store `v'_`j'
	}
	}

forval j=1/5 {
est table covid_gene_`j' covid_preexisting_`j' covid_jobs_`j' covid_healthcare_`j'  covid_neighborhood_`j' covid_flout_protocols_`j' , b(%9.2f) se style(col) eq(1) stats(N) keep(race_bio_identity pid7cata ed6cat age01 _cons)
est table covid_gene_`j' covid_preexisting_`j' covid_jobs_`j' covid_healthcare_`j'  covid_neighborhood_`j' covid_flout_protocols_`j' , b(%9.2f) star(.05 .01 .001) style(col) eq(1) stats(N) keep(race_bio_identity pid7cata ed6cat age01 _cons)
}


**********FOOTNOTE - SEPARATE SAMPLE ESTIMATION
//pairwise comparisons:
//looking at the effect of race_bio_identity among:
//Asians vs. Blacks, Hispanics, W Dem, W GOP
//Blacks vs. Hispanics, W Dem, W GOP
//Hispanics vs. W Dem, W GOP
//W Dem vs. W GOP
*10 total comparisons

forval j=1/5 {
	foreach v of varlist covid_gene covid_preexisting covid_jobs covid_healthcare covid_neighborhood covid_flout_protocols {
	reg `v' race_bio_identity pid7cata ed6cat age01 black hispanic api if fivegroups==`j' & ref_covid_battery~=6
est store `v'`j'
	}
	}
	
suest covid_gene1 covid_gene2
test [covid_gene1_mean]race_bio_identity = [covid_gene2_mean]race_bio_identity
suest covid_gene1 covid_gene3
test [covid_gene1_mean]race_bio_identity = [covid_gene3_mean]race_bio_identity
suest covid_gene1 covid_gene4
test [covid_gene1_mean]race_bio_identity = [covid_gene4_mean]race_bio_identity
/*p=0.026*/
suest covid_gene1 covid_gene5
test [covid_gene1_mean]race_bio_identity = [covid_gene5_mean]race_bio_identity
suest covid_gene2 covid_gene3
test [covid_gene2_mean]race_bio_identity = [covid_gene3_mean]race_bio_identity
suest covid_gene2 covid_gene4
test [covid_gene2_mean]race_bio_identity = [covid_gene4_mean]race_bio_identity
suest covid_gene2 covid_gene5
test [covid_gene2_mean]race_bio_identity = [covid_gene5_mean]race_bio_identity
suest covid_gene3 covid_gene4
test [covid_gene3_mean]race_bio_identity = [covid_gene4_mean]race_bio_identity
/*p=0.0405*/
suest covid_gene3 covid_gene5
test [covid_gene3_mean]race_bio_identity = [covid_gene5_mean]race_bio_identity
suest covid_gene4 covid_gene5
test [covid_gene4_mean]race_bio_identity = [covid_gene5_mean]race_bio_identity 
/*p=0.0105*/

//analyzing the four other groups together, without WDem//
reg covid_gene race_bio_identity pid7cata ed6cat age01 black hispanic api if fivegroups~=4 & ref_covid_battery~=6

log close

translate "Anoll Kam Marcellin Lucid Analyses.smcl" "Anoll Kam Marcellin Lucid Analyses.pdf"
